package com.lanou.dllo.soccernews.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lanou.dllo.soccernews.bean.greendao.RecommendEntity;
import com.lanou.dllo.soccernews.fragment.homelinefragment.RecommendFragment;

import java.util.List;

/**
 * Created by dllo on 15/10/21.
 */
public class HeadlineViewpageAdapter extends FragmentPagerAdapter {


    List<RecommendEntity> recommendEntities;

    public void addData(List<RecommendEntity> recommendEntities) {
        this.recommendEntities = recommendEntities;

        notifyDataSetChanged();
    }

    public HeadlineViewpageAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {

        RecommendEntity recommendEntity = recommendEntities.get(position);
        String title = recommendEntity.getTitle();
        String imgUrl = recommendEntity.getThumb();

        return RecommendFragment.getInstance(title, imgUrl);
    }

    @Override
    public int getCount() {
        return recommendEntities != null && recommendEntities.size() > 0 ?
                recommendEntities.size() : 0;
    }
}
